package com.tensquare.search.service;

import com.tensquare.search.dao.ArticleDao;
import com.tensquare.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * @author 11752
 */
@Service
public class ArticleService {

    @Autowired
    private ArticleDao articleDao;

    /*@Autowired
    private IdWorker idWorker;*/

    /**
     * 添加文章
     *
     * @param article 文章数据
     */
    public void add(Article article) {
        // article.setId(idWorker.nextId()+"");
        articleDao.save(article);
    }


    /**
     * 根据关键字在标题或者内容中查找
     * @param key 关键字
     * @param page 页码
     * @param size 页大小
     * @return 数据
     */
    public Page<Article> findByKey(String key, int page, int size) {
        Pageable pageable = PageRequest.of(page - 1, size);
        return articleDao.findByTitleOrContentLike(key, key, pageable);
    }
}
